package controller;

import ui.Main;
import common.*;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

import java.io.ObjectOutputStream;
import java.net.Socket;

public class AddControl {
    private static User user= Main.userClientService.getUser();
    private static Socket socket=Main.userClientService.getSocket();
    private ObjectOutputStream oos;
    @FXML
    private TextField code;
    @FXML
    private Label error;
    public static Course course;
    @FXML
    public void ok(){
        if(code.getText().equals("")){
            error.setText("课程号为空");
            return;
        }
        try {
            ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
            Message ms=new Message();
            ms.setState(MessageType.add_Class);//发送请求
            oos.writeObject(ms);
            oos.writeObject(new StuMidClass(user.getId(),code.getText()));//将课程号发过去
        } catch (Exception e) {
            System.out.println("添加课程失败");
        }finally {
            Stage stage=(Stage) error.getScene().getWindow();
            stage.close();
        }
    }
}
